﻿using CrystalDecisions.CrystalReports.Engine;
using DSPL.Contracts.Command;
using DSPL.Contracts.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace DSPL.Common.ViewModel
{
    public class ReportViewerViewModel : BaseViewModel
    {
        private ICommand formLoad;
        Window parentWindow;
        private ReportDocument reportDocument;
        private string reportTitle;

        public ReportDocument ReportDocument
        {
            get { return reportDocument; }
            set { reportDocument = value;
            OnPropertyChanged("ReportDocument");
            }
        }
        

        public ReportViewerViewModel(ReportDocument report, string reportName)
        {
            ReportDocument = report;
            reportTitle = reportName;
        }
        
        public ICommand FormLoad
        {
            get
            {
                if (this.formLoad == null)
                    this.formLoad = new RelayCommand(FormLoadExecuted);
                return this.formLoad;
            }
            set { formLoad = value; }
        }

        private void FormLoadExecuted(object obj)
        {
            if (obj != null)
            {
                parentWindow = (Window)obj;
                parentWindow.Title = "Report Generation - " + reportTitle;
                parentWindow.WindowState = WindowState.Maximized;
            }
        }
    }
}
